﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PTExpress.Views
{
    /// <summary>
    /// Interaction logic for ucXToolBar.xaml
    /// </summary>
    public partial class ucXToolBar : UserControl
    {
        public ucXToolBar()
        {
            InitializeComponent();
            this.AddHandler(Button.ClickEvent, new RoutedEventHandler(ToolBarButton_Click));

        }



        private void ToolBar_Loaded(object sender, RoutedEventArgs e)
        {
            if (Cm_Save == null)
                (this.FindName("btnSave") as Button).Visibility = Visibility.Collapsed;
            if (Cm_New == null)
                (this.FindName("btnNew") as Button).Visibility = Visibility.Collapsed;
            if (Cm_Exit == null)
                (this.FindName("btnExit") as Button).Visibility = Visibility.Collapsed;
            if (Cm_Apply == null)
                (this.FindName("btnApply") as Button).Visibility = Visibility.Collapsed;
            if (Cm_Apply == null)
                (this.FindName("btnReport") as Button).Visibility = Visibility.Collapsed;

        }

        public delegate void Execute();
        public event Execute Cm_Save;
        public event Execute Cm_Exit;
        public event Execute Cm_New;
        public event Execute Cm_Apply;
        public event Execute Cm_Report;

        private void ToolBarButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            Button btn = (e.OriginalSource as Button);
            try
            {
                switch (btn.Name)
                {
                    case "btnSave":
                        {
                            if (Cm_Save != null)
                                Cm_Save();
                        }
                        break;
                    case "btnExit":
                        {
                            if (Cm_Exit != null)
                                Cm_Exit();
                        }
                        break;
                    case "btnNew":
                        {
                            if (Cm_New != null)
                                Cm_New();
                        }
                        break;
                    case "btnApply":
                        {
                            if (Cm_Apply != null)
                                Cm_Apply();
                        }
                        break;
                    case "btnReport":
                        {
                            if (Cm_Report != null)
                                Cm_Report();
                        }
                        break;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

    }
}
